import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Demo_InputStream {
    public static void main(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("d:/test/test1/file1.txt")){
            Scanner scanner = new Scanner(inputStream);
            while(scanner.hasNext()){
                String s = scanner.next();
                System.out.println(s);
            }
        }
    }
    public static void main2(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("d:/test/test1/file1.txt")){
            byte[] b = new byte[1024];
            while(true){
                int i = inputStream.read(b);
                if(i == -1){
                    break;
                }
                for(int j = 0; j < i; j++){
                    System.out.printf("%c", b[j]);
                }
            }
        }
    }
    public static void main1(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("d:/test/test1/file1.txt")){
            while(true){
                int i = inputStream.read();
                if(i == -1){
                    break;
                }
                System.out.printf("%c", i);
            }
        }
    }
}
